LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-07-2007, 01:39 AM   #1
RAdams
Member
 
Registered: May 2006
Location: Cincinnati, Ohio
Distribution: Ubuntu
Posts: 256

Rep: Reputation: 30
Red face How do I make a text file in Bash?


All I want to do is write a script that makes a text file called "test" containing the text:
Code:
Hello World!
This is my stupid text file.
in the directory /foo/bar

I know it can be done easily... but I don't know how.

 
Old 01-07-2007, 01:44 AM   #2
RAdams
Member
 
Registered: May 2006
Location: Cincinnati, Ohio
Distribution: Ubuntu
Posts: 256

Original Poster
Rep: Reputation: 30
Solved. Thanks to Google, I remembered something very basic I had forgotten:
Code:
>>
le sigh. So the solution is this:

Code:
echo -e "Hello World!\nThis is my stupid text file." >> /foo/bar/test

Last edited by RAdams; 01-08-2007 at 12:44 AM.
 
Old 01-14-2007, 05:56 AM   #3
fotoguy
Senior Member
 
Registered: Mar 2003
Location: Brisbane Queensland Australia
Distribution: Custom Debian Live ISO's
Posts: 1,291

Rep: Reputation: 62
There is also another way that works better especially if you need to add lots of lines of text, you can use the cat commad and run it through a script.

Code:
#!/bin/sh
cat > test << EOF
Hello World!
This is my stupid text file.

You
can also
have
a whole lot
more text and
lines
EOF
You can also point it to a directory that you want the file created in.

Code:
#!/bin/sh
cat > /home/billy/test << EOF
Hello World!
This is my stupid text file.

You
can also
have
a whole lot
more text and
lines
EOF
 
  


Reply

Tags
bash



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Read variables from a text file in Bash jakev383 Linux - General 5 12-20-2006 07:29 AM
how to change some text of a certain line of a text file with bash and *nix scripting alred Programming 6 07-10-2006 11:55 AM
bash: split text file iluvatar Programming 4 08-22-2005 08:58 AM
Create a text file using Bash Boffy Programming 5 03-14-2005 09:06 PM
send text to file bash bendeco13 Linux - General 6 11-01-2004 06:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration